﻿using BCCommon.TMS.Order;
using BCCommon.TMS.Transport;
using BCEntity.TMS.Driver;
using BCEntity.TMS.KanBan.AgentKanBan;
using BCEntity.TMS.Order.Order;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace BCData.TMS.Order.Order
{
    /// <summary>
    /// 订单
    /// </summary>
    public interface IOrderData
    {
        /// <summary>
        /// 检查订单编号是否存在
        /// </summary>
        /// <param name="orderNo">订单编号</param>
        /// <returns></returns>
        Task<bool> CheckOrderNoExists(string orderNo);
        /// <summary>
        /// 创建订单
        /// </summary>
        /// <param name="entity">订单信息</param>
        /// <returns></returns>
        Task<OrderEntity> Add(OrderEntity entity);
        /// <summary>
        /// 获取订单信息
        /// </summary>
        /// <param name="orderNo">订单编号</param>
        /// <returns></returns>
        Task<OrderEntity> GetEntity(string orderNo);
        /// <summary>
        /// 获取订单信息
        /// </summary>
        /// <param name="orderId">订单Id</param>
        /// <returns></returns>
        Task<OrderEntity> GetEntity(long orderId);
        /// <summary>
        /// 获取订单信息
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="orderId">订单Id</param>
        /// <returns></returns>
        Task<OrderEntity> GetEntityWithUser(long userId, long orderId);
        /// <summary>
        /// 获取订单信息
        /// </summary>
        /// <param name="driverId">司机Id</param>
        /// <param name="orderId">订单Id</param>
        /// <returns></returns>
        Task<OrderEntity> GetEntityWithDriver(long driverId, long orderId);
        /// <summary>
        /// 删除订单--仅可在下单是业务失败时回滚使用
        /// </summary>
        /// <param name="orderId">订单Id</param>
        /// <returns></returns>
        Task<bool> Delete(long orderId);
        /// <summary>
        /// 获取订单列表
        /// </summary>
        /// <param name="companyId">公司Id</param>
        /// <param name="vehicleNo">车牌号</param>
        /// <param name="provinceCode">省份编码</param>
        /// <param name="communityCode">城市编码</param>
        /// <param name="countyCode">区县编码</param>
        /// <param name="orderStatus">订单状态</param>
        /// <param name="goodsName">商品名称</param>
        /// <param name="userId">用户Id</param>
        /// <param name="vehicleId">车辆Id</param>
        /// <param name="endProvinceCode">目的地省份编码</param>
        /// <param name="endCommunityCode">目的地城市编码</param>
        /// <param name="endCountyCode">目的地区县编码</param>
        /// <param name="goodsWeightLeft">货物重量左区间值</param>
        /// <param name="goodsWeightRight">货物重量右区间值</param>
        /// <param name="vehicleTypeId">车型ID</param>
        /// <param name="businessType">业务类型(订单类型)</param>
        /// <param name="vehicleCategoryName">车辆分类名称</param>
        /// <param name="phone">手机号</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param> 
        /// <param name="ascending">升序</param>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="pageSize">当前页大小</param>
        /// <returns></returns>
        Task<(IEnumerable<OrderEntity>, long)> GetOrderEntities(int companyId, string vehicleNo, string provinceCode, string communityCode, string countyCode, OrderStatus? orderStatus, string goodsName, long? userId, long? vehicleId,
            string endProvinceCode, string endCommunityCode, string endCountyCode, decimal? goodsWeightLeft, decimal? goodsWeightRight, int? vehicleTypeId, TransportBusinessType? businessType, string vehicleCategoryName, string phone,
            DateTime? start, DateTime? end, bool? ascending, int pageIndex = 1, int pageSize = 10);
        /// <summary>
        /// 获取退款订单
        /// </summary>
        /// <param name="provinceId">省份Id</param>
        /// <param name="communityId">城市Id</param>
        /// <param name="countyId">区县Id</param>
        /// <param name="hasRefund">已退款</param>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="pageSize">每页数据条数</param>
        /// <returns></returns>
        Task<(IEnumerable<OrderEntity>, int)> GetRefundOrders(string provinceId, string communityId, string countyId, bool? hasRefund, int pageIndex, int pageSize);
        /// <summary>
        /// 用户端App专用订单列表
        /// </summary>
        /// <param name="userAppOrderStatus">用户端订单状态</param>
        /// <param name="userId">用户Id</param>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="pageSize">每页数据条数</param>
        /// <returns></returns>
        Task<(IEnumerable<OrderEntity>, int)> GetOrderEntities(UserAppOrderStatus? userAppOrderStatus, long? userId, int pageIndex, int pageSize);
        /// <summary>
        /// 司机端App专用订单列表
        /// </summary>
        /// <param name="driverAppOrderStatus">司机端订单状态</param>
        /// <param name="userId">用户Id</param>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="pageSize">每页数据条数</param>
        /// <returns></returns>
        Task<(IEnumerable<OrderEntity>, int)> GetOrderEntities(DriverAppOrderStatus? driverAppOrderStatus, long? userId, int pageIndex, int pageSize);
        /// <summary>
        /// 司机端App专用订单列表
        /// </summary>
        /// <param name="currentDriver">当前登录司机</param>
        /// <param name="orderStatus">订单状态</param>
        /// <param name="transportBusinessType">运输业务类型</param>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="pageSize">每页数据条数</param>
        /// <returns></returns>
        Task<(IEnumerable<OrderEntity>, int)> GetOrderEntities(DriverEntity currentDriver, OrderStatus orderStatus, TransportBusinessType? transportBusinessType, int pageIndex, int pageSize);


        #region 车辆补充原始回单
        /// <summary>
        /// 车辆补充原始回单
        /// </summary>
        /// <param name="orderEntity">订单信息</param>
        /// <returns></returns>
        Task<bool> AddSourceReceiptPhoto(OrderEntity orderEntity);
        #endregion

        #region 车辆上传签收回单
        /// <summary>
        /// 车辆上传签收回单
        /// </summary>
        /// <param name="orderEntity">订单信息</param>
        /// <returns></returns>
        Task<bool> AddAcceptanceReceiptPhoto(OrderEntity orderEntity);

        #endregion
        /// <summary>
        /// 代理商端App专用订单列表
        /// </summary>
        /// <param name="agentAppOrderStatus">代理商端订单状态</param>
        /// <param name="agentRecordId">代理商Id</param>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="pageSize">每页数据条数</param>
        /// <returns></returns>
        Task<(IEnumerable<OrderEntity>, int)> GetOrderEntities(AgentAppOrderStatus? agentAppOrderStatus, long agentRecordId, int pageIndex, int pageSize);
        /// <summary>
        /// 获取订单Id列表
        /// </summary>
        /// <param name="vehicleId">车辆Id</param>
        /// <returns></returns>
        Task<IEnumerable<long>> GetOrderIds(long vehicleId);
        /// <summary>
        /// 取消订单
        /// </summary>
        /// <param name="orderEntity">订单信息</param>
        /// <returns></returns>
        Task<bool> CancelOrder(OrderEntity orderEntity);
        /// <summary>
        /// 修改订单状态为下单
        /// </summary>
        /// <param name="orderId">订单Id</param>
        /// <returns></returns>
        Task<bool> UpdateOrderStatusPlaceOrder(long orderId);
        /// <summary>
        /// 修改订单状态为运输中
        /// </summary>
        /// <param name="orderId">订单Id</param>
        /// <returns></returns>
        Task<bool> UpdateOrderStatusTransporting(long orderId);
        /// <summary>
        /// 修改订单状态为已签收
        /// </summary>
        /// <param name="orderId">订单Id</param>
        /// <returns></returns>
        Task<bool> UpdateOrderStatusAcceptance(long orderId);
        /// <summary>
        /// 修改订单状态为已完成
        /// </summary>
        /// <param name="orderId">订单Id</param>
        /// <param name="orderNo">订单编号</param>
        /// <returns></returns>
        Task<bool> UpdateOrderStatusComplete(long orderId, string orderNo);
        /// <summary>
        /// 回滚订单状态
        /// </summary>
        /// <param name="orderId">订单Id</param>
        /// <param name="orderNo">订单编号</param>
        /// <param name="orderStatus">订单状态</param>
        /// <returns></returns>
        Task<bool> RollbackOrderStatus(long orderId, string orderNo, OrderStatus orderStatus);
        /// <summary>
        /// 修改订单状态为已到达
        /// </summary>
        /// <param name="orderId">订单Id</param>
        /// <returns></returns>
        Task<bool> UpdateOrderStatusArrived(long orderId);
        /// <summary>
        /// 修改订单状态为已关闭
        /// </summary>
        /// <param name="orderId">订单Id</param>
        /// <param name="orderNo">订单编号</param>
        /// <returns></returns>
        Task<bool> UpdateOrderStatusClosed(long editerId, string editer, long orderId, string orderNo, string closeOrderContent);
        /// <summary>
        /// 修改订单价格
        /// </summary>
        /// <param name="orderId">订单Id</param>
        /// <param name="freightCostAmount">运费总金额</param>
        /// <param name="orderAmount">订单总金额</param>
        /// <returns></returns>
        Task<bool> UpdateOrderAmount(long orderId, decimal freightCostAmount, decimal orderAmount);
        /// <summary>
        /// 修改订单发货人付款时间
        /// </summary>
        /// <param name="orderId">订单Id</param>
        /// <returns></returns>
        Task<bool> UpdateOrderShippingPayTime(long orderId);
        /// <summary>
        /// 修改订单收货人付款时间
        /// </summary>
        /// <param name="orderId">订单Id</param>
        /// <returns></returns>
        Task<bool> UpdateOrderConsigneePayTime(long orderId);
        /// <summary>
        /// 修改订单指派信息
        /// </summary>
        /// <param name="orderId">订单Id</param>
        /// <param name="driverId">司机Id</param>
        /// <param name="driverName">司机姓名</param>
        /// <param name="driverPhone">司机电话</param>
        /// <param name="vehicleNo">车牌号</param>
        /// <param name="orderStatus">订单状态</param>
        /// <param name="assignEditerId">指派人Id</param>
        /// <param name="assignEditer">指派人名称</param>
        /// <returns></returns>
        Task<bool> UpdateOrderAssigned(long orderId, long driverId, string driverName, string driverPhone, string vehicleNo, OrderStatus orderStatus, long assignEditerId, string assignEditer);


        /// <summary>
        /// 修改订单总金额结算结果
        /// </summary>
        /// <param name="orderId">订单Id</param>
        /// <param name="orderAmountSettleResultType">订单总金额结算结果状态</param>
        /// <returns></returns>
        Task<bool> UpdateOrderAdmountSettleResult(long orderId, OrderAmountSettleResultType orderAmountSettleResultType);

        /// <summary>
        /// 获取订单数量
        /// </summary>
        /// <param name="agentRecordId">代理商ID</param>
        /// <param name="orderStatus">订单状态</param>
        /// <param name="completeTime">订单完成时间</param>
        /// <returns></returns>
        Task<long> GetListByAgentRecordId(long agentRecordId, OrderStatus orderStatus, DateTime? completeTime);

        /// <summary>
        /// 获取订单统计信息
        /// </summary>
        /// <param name="agentRecordId">代理商ID</param>
        /// <param name="orderStatus">订单状态</param>
        /// <param name="completeTime">订单完成时间</param>
        /// <returns></returns>
        Task<IEnumerable<OrderStatisticInfoEntity>> GetOrderStatisticInfo(long agentRecordId, OrderStatus orderStatus, DateTime? completeTime);

        /// <summary>
        /// 获取订单区域分析信息
        /// </summary>
        /// <param name="agentRecordId">代理商ID</param>
        /// <param name="orderStatus">订单状态</param>
        /// <param name="completeTime">完成时间</param>
        /// <returns></returns>
        Task<IEnumerable<OrderAreaAnalysisDetailEntity>> GetOrderAreaAnalysisDetailList(long agentRecordId, OrderStatus orderStatus, DateTime? completeTime);
        /// <summary>
        /// 更新订单签收人信息
        /// </summary>
        /// <param name="orderEntity">订单信息</param>
        /// <returns></returns>
        Task<bool> UpdateOrderSignPersonInfo(OrderEntity orderEntity);
        /// <summary>
        /// 更新订单司机信息
        /// </summary>
        /// <param name="orderId">订单Id</param>
        /// <param name="driverId">司机Id</param>
        /// <param name="driverName">司机姓名</param>
        /// <param name="driverPhone">司机电话</param>
        /// <param name="vehicleNo">车牌号</param>
        /// <returns></returns>
        Task<bool> UpdateOrderDriver(long orderId, long driverId, string driverName, string driverPhone, string vehicleNo);
    }
}